package com.musicdaze;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.ListSelectionModel;
import javax.swing.JSplitPane;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridLayout;
import javax.swing.border.EtchedBorder;
import javax.swing.border.TitledBorder;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import java.lang.ClassNotFoundException;
import java.lang.InstantiationException;
import java.lang.IllegalAccessException;

public class SwingThing {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		try
		{
			UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName());
		}
	 
		catch ( UnsupportedLookAndFeelException e ) { }
		catch ( ClassNotFoundException e ) { }
		catch ( InstantiationException e ) { }
		catch ( IllegalAccessException e ) { }
		
		JFrame frame = new JFrame();
		
		frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
		frame.setTitle( "MusicDaze" );
		//frame.setLocationRelativeTo( null );
		frame.setPreferredSize( new Dimension( 300, 350 ) );
		frame.setResizable( true );
		//frame.setLayout( new BoxLayout( frame, BoxLayout.PAGE_AXIS ) );
		JPanel framePanel = new JPanel();
		framePanel.setLayout( new BoxLayout( framePanel, BoxLayout.PAGE_AXIS ) );
		
		JPanel searchPanel = new JPanel();
		searchPanel.setPreferredSize( new Dimension( 300, 130 ) );
		searchPanel.setMaximumSize( new Dimension( 300, 130 ) );
		searchPanel.setBorder( new TitledBorder( "Search" ) );
		searchPanel.setLayout( new BoxLayout( searchPanel, BoxLayout.PAGE_AXIS ) );
		
		JPanel topSearchPanel = new JPanel();
		JLabel searchLabel = new JLabel( "Search music: " );
		JTextField searchField = new JTextField( 22 );
		topSearchPanel.add( searchLabel, BorderLayout.EAST );
		topSearchPanel.add( searchField );
		
		JPanel bottomSearchPanel = new JPanel();
		bottomSearchPanel.setLayout( new BoxLayout( bottomSearchPanel, BoxLayout.LINE_AXIS) );
		JPanel sameSizeButtonPanel = new JPanel();
		sameSizeButtonPanel.setLayout( new GridLayout( 1, 2 ) );
		JButton playNow = new JButton( "Play now!" );
		JButton createSchedule = new JButton( "Create schedule... " );
		playNow.setPreferredSize( createSchedule.getPreferredSize() );
		sameSizeButtonPanel.add( playNow );
		sameSizeButtonPanel.add( createSchedule );
		bottomSearchPanel.add( sameSizeButtonPanel );
		
		searchPanel.add( Box.createRigidArea( new Dimension( 0, 10 ) ) );
		searchPanel.add( topSearchPanel );
		//searchPanel.add( Box.createRigidArea( new Dimension( 0, 10 ) ) );
		searchPanel.add( bottomSearchPanel );
		searchPanel.add( Box.createRigidArea( new Dimension( 0, 10 ) ) );
		
		System.out.println( searchPanel.getPreferredSize() );
		
		JPanel schedulePanel = new JPanel();
		schedulePanel.setBorder( new TitledBorder( "Schedules" ) );
		schedulePanel.setLayout( new BoxLayout( schedulePanel, BoxLayout.PAGE_AXIS ) );
		
		JPanel topSchedulePanel = new JPanel();
		//topSchedulePanel.setBorder( new EtchedBorder() );
		Object[] schedules = {"schedule1", "schedule2", "schedule3" };
		JList scheduleList = new JList( schedules );
		scheduleList.setSelectionMode( ListSelectionModel.SINGLE_SELECTION );
		scheduleList.setLayoutOrientation( JList.VERTICAL );
		scheduleList.setVisibleRowCount( 6 );
		
		JScrollPane listScroller = new JScrollPane( scheduleList );
		listScroller.setPreferredSize( new Dimension( 250, 120 ) );
		
		topSchedulePanel.add( listScroller );
		
		JPanel bottomSchedulePanel = new JPanel();
		//bottomSchedulePanel.setBorder( new EtchedBorder() );
		bottomSchedulePanel.setLayout( new BoxLayout( bottomSchedulePanel, BoxLayout.LINE_AXIS ) );
		JButton editButton = new JButton( "Edit" );
		editButton.setMinimumSize( new Dimension( playNow.getPreferredSize() ) );
		//System.out.println( "minimum size: " + editButton.getMinimumSize() );
		bottomSchedulePanel.add( Box.createRigidArea( new Dimension( 150, 0 ) ) );
		bottomSchedulePanel.add( editButton );
		bottomSchedulePanel.add( Box.createRigidArea( new Dimension( 10, 0 ) ) );
		
		//System.out.println( "size" + playNow.getPreferredSize() );
		
		schedulePanel.add( topSchedulePanel );
		schedulePanel.add( Box.createRigidArea( new Dimension( 0, 5 ) ) );
		schedulePanel.add( bottomSchedulePanel );
		schedulePanel.add( Box.createRigidArea( new Dimension( 0, 5 ) ) );
		/*
		JSplitPane splitPane = new JSplitPane( JSplitPane.HORIZONTAL_SPLIT );
		splitPane.setLeftComponent( new JButton( "left" ) );
		splitPane.setRightComponent( new JButton( "right" ) );
		splitPane.setOneTouchExpandable( true );
		*/
		//frame.setLayout( new GridLayout( 2, 1 ) );
		framePanel.add( searchPanel );
		framePanel.add( schedulePanel );
		//framePanel.add( splitPane );
		frame.add( framePanel );
		
		//System.out.println( frame.getWidth() );
		//System.out.println( frame.getPreferredSize() );
		
		frame.pack();
		frame.setVisible( true );
	}

}
